from django.urls import path, re_path
from rest_framework.routers import DefaultRouter
from . import views

router = DefaultRouter()
app_name = 'api'

urlpatterns = [
    # 操作 posts
    re_path(r'user/posts/(?P<pk>[0-9a-zA-Z]{22})/', views.UserPostsView.as_view({
        'get': 'retrieve',
        'delete': 'destroy'
    }), name='user_posts_detail'),
    path('user/posts/', views.UserPostsView.as_view({
        'get': 'list',
        'post': 'create'
    }), kwargs={'pk': None}, name='user_posts'),

    # 查看 posts
    re_path(r'posts/(?P<pk>[0-9a-zA-Z]{22})/', views.PostsView.as_view({
        'get': 'retrieve'
    }), name='posts_detail'),
    path('posts/', views.PostsView.as_view({
        'get': 'list'
    }), kwargs={'pk': None}, name='posts'),
    # type
    path('user/types/', views.UserTypesView.as_view(), kwargs={'pk': None}, name='types'),

    # topics
    re_path('user/topics/(?P<pk>[0-9a-zA-Z]{22})/', views.UserTopicsView.as_view({
        'get': 'retrieve',
        'delete': 'destroy'
    }), name='topic_detail'),
    path('user/topics/', views.UserTopicsView.as_view({
        'get': 'list',
        'post': 'create'
    }), kwargs={'pk': None}, name='topics'),

    # topics
    re_path('topics/(?P<pk>[0-9a-zA-Z]{22})/', views.TopicsView.as_view({
        'get': 'retrieve'
    }), name='topic_detail'),
    path('topics/', views.TopicsView.as_view({
        'get': 'list',
    }), name='topics'),

    # 上传
    path('upload/', views.Upload.as_view(), name='upload'),

]
